package com.crawler.util;

import java.awt.Color;
import java.awt.image.BufferedImage;

public class ImageProcessing {
    public static void processing(BufferedImage imagea) {
        int minY = 0;
        int height = 40;
        int minX = 0;
        int width = 90;
        for (int y = minY; y < height; y++) {
            for (int x = minX; x < width; x++) {
                int rgb = imagea.getRGB(x, y);
                Color color = new Color(rgb); // 根据rgb的int值分别取得r,g,b颜色。
                int gray = (int) (0.3 * color.getRed() + 0.59 * color.getGreen() + 0.11 * color.getBlue());
                Color newColor = new Color(gray, gray, gray);
                imagea.setRGB(x, y, newColor.getRGB());
            }
        }
        for (int y = minY; y < height; y++) {
            for (int x = minX; x < width; x++) {
                int rgb = imagea.getRGB(x, y);
                Color color = new Color(rgb); // 根据rgb的int值分别取得r,g,b颜色。
                Color newColor = new Color(255 - color.getRed(), 255 - color.getGreen(), 255 - color.getBlue());
                imagea.setRGB(x, y, newColor.getRGB());
            }
        }
        for (int y = minY; y < height; y++) {
            for (int x = minX; x < width; x++) {
                int rgb = imagea.getRGB(x, y);
                Color color = new Color(rgb); // 根据rgb的int值分别取得r,g,b颜色。
                int value = 255 - color.getBlue();
                if (value > 122) {
                    Color newColor = new Color(0, 0, 0);
                    imagea.setRGB(x, y, newColor.getRGB());
                } else {
                    Color newColor = new Color(255, 255, 255);
                    imagea.setRGB(x, y, newColor.getRGB());
                }
            }
        }
    }
}
